<template>
  <el-dialog v-if="load" :close-on-click-modal="false" title="关联店铺" v-model="visible" append-to-body width="800px" @close="handleClose">
    <vxe-table :data="data">
      <vxe-column title="平台" field="platform_name"></vxe-column>
      <vxe-column title="店铺" field="shop_name"></vxe-column>
      <vxe-column title="首选业务员" field="preferred_saleman_name"></vxe-column>
      <vxe-column title="组织" field="first_level_department"></vxe-column>
      <vxe-column title="操作">
        <template #default="{row}">
          <el-link type="primary" @click="view(row)">查看</el-link>
        </template>
      </vxe-column>
    </vxe-table>
    <template #footer>
      <el-button @click="close">关 闭</el-button>
    </template>
  </el-dialog>
</template>

<script setup>
import api from '../api'
import { ElMessage } from 'element-plus'
const load = ref(false)
const visible = ref(false)
let loadings = reactive({})
const data = ref([])

const emit = defineEmits(['close', 'success'])

const router = useRouter()
const view = (row) => {
  sessionStorage.setItem('_setForm', JSON.stringify(row))
  close()
  router.push('/shop/list')
}

// 打开弹窗
const open = async (brand_id) => {
  if (!load.value) {
    load.value = true
    await 1
  }
  data.value = []
  const res = await api.shopList({brand_id})
  data.value = res.data
  loadings = reactive({})
  visible.value = true
}
// 关闭弹窗
const close = () => {
  visible.value = false
}

const handleClose = () => {
  emit('close')
}

defineExpose({ open })
</script>